package com.example.springboot.util;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * Created by tang on 2018/1/4.
 */
public class JdbcTemplateUtils {
    private static JdbcTemplate jdbcTemplate;

    private JdbcTemplateUtils() {
    }

    public static JdbcTemplate jdbcTemplate() {

        if (jdbcTemplate == null) {
            jdbcTemplate = createJdbcTemplate();
        }

        return jdbcTemplate;
    }

    private static JdbcTemplate createJdbcTemplate() {
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        druidDataSource.setUrl("jdbc:mysql://localhost:3306/shiro");
        druidDataSource.setUsername("root");
        druidDataSource.setPassword("root");

        return new JdbcTemplate(druidDataSource);
    }


}
